from tortoise import fields

from app.models.base import TimestampMixin, BaseModel

__all__ = [
    'Upload',
    'UploadFolder',
]


class Upload(BaseModel, TimestampMixin):
    """上传实体"""

    # id = fields.BigIntField(pk=True, index=True, description='主键')
    folder_id = fields.IntField(description='分类ID')
    channel = fields.SmallIntField(null=False, description='上传来源（1 管理后台 2 Web端）')
    uid = fields.IntField(null=False, description='用户ID')
    type = fields.IntField(null=False, description='文件类型: 10=图片, 20=视频, 30=音频, 40=文件')
    storage = fields.CharField(max_length=20, null=True, default='local', description='存储文件')
    # domain = fields.CharField(max_length=200, null=True, default='', description='存储域名')
    name = fields.CharField(max_length=100, null=True, default='', description='文件名称')
    url = fields.CharField(max_length=200, null=True, default='', description='文件路径')
    ext = fields.CharField(max_length=10, null=False, default='', description='文件扩展')
    size = fields.IntField(null=False, description='文件大小')
    is_deleted = fields.BooleanField(default=False, description='是否删除: [False=正常, True=删除]')

    class Meta:
        table_description = "上传表"
        table = "upload"


class UploadFolder(BaseModel, TimestampMixin):
    """上传文件分组实体"""

    # id = fields.BigIntField(pk=True, index=True, description='主键')
    pid = fields.IntField(null=False, default=0, description='上级ID')
    name = fields.CharField(max_length=60, null=False, default='', description='名称')
    sort = fields.SmallIntField(null=False, default=10, description='排序')
    is_deleted = fields.BooleanField(default=False, description='是否删除: [False=正常, True=删除]')

    class Meta:
        table_description = "上传文件分组表"
        table = "upload_folder"
        fields = ('id', 'name', 'sort', 'status', 'create_time', 'update_time')  # 不包含敏感字段
